﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace Presentation
{
    public partial class CapNhatPhieuThue : Form
    {
        public PhieuThuePhongDTO phieuThue=new PhieuThuePhongDTO();
        public CapNhatPhieuThue()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TiepNhanKhachMoi form = new TiepNhanKhachMoi();
            form.ShowDialog();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            CapNhatKhach form = new CapNhatKhach();
            form.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
                try
                {
                    PhieuThuePhongDTO phieuDuocChon= new PhieuThuePhongDTO();
                    PhongDTO phong = (PhongDTO)cbbTenPhong.Items[cbbTenPhong.SelectedIndex];
                    phieuDuocChon.Phong = phong;
                    phieuDuocChon.NgayBatDauThue = dt_NgayBatDauThue.Value;
                  
                    bool ketQua = PhieuThuePhongBUS.capNhat(phieuThue);
                    //bool ketQua = PhieuThuePhongBUS.capNhat(phieuDuocChon);
                    if (ketQua == false)
                        throw new Exception();
                    
                    MessageBox.Show("Cập nhật thành công");
                    //QuanLyPhieuThue
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Cập nhật thất bại");
                }
        }

        private void CapNhatPhieuThue_Load(object sender, EventArgs e)
        {
            layDSPhong();
            layThongTinPhieuThue();
        }
 


        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            PhongDTO phong = (PhongDTO)cbbTenPhong.Items[cbbTenPhong.SelectedIndex];
        }
        public void truyenPhieu(PhieuThuePhongDTO phieuDuocChon)
        {
            phieuThue = phieuDuocChon;
        }
        private void layDSPhong()
        {
            List<PhongDTO> danhSachPhong = PhongBUS.layDSPhong();
            cbbTenPhong.DataSource = danhSachPhong;
            cbbTenPhong.DisplayMember = "TenPhong";

        }
        public void layThongTinPhieuThue()
        {
            cb_MaPhieuThue.Text = phieuThue.MaPhieuThue.ToString();
            cbbTenPhong.Text = phieuThue.Phong.TenPhong.ToString();
            dt_NgayBatDauThue.Text = phieuThue.NgayBatDauThue.ToString();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}
